use log::info;
use tokio::sync::mpsc;
use crate::connection_manager::event::{ConnectionEvent, ConnectionManageable};
pub mod event;
pub mod connection;

pub fn start<T: ConnectionManageable + Send + 'static>(manageable: T) -> mpsc::UnboundedSender<Box<dyn ConnectionEvent>> {
    let (sender, mut receiver) = mpsc::unbounded_channel::<Box<dyn ConnectionEvent>>();

    tokio::spawn(async move {
        info!("client connection manager run");
        let mut manager = manageable;
        while let Some(message) = receiver.recv().await {
            manager.handle_event(message);
        }
    });

    sender
}